package cn.trigram.mapper.dynamic;

import static cn.trigram.mapper.dynamic.MqTransactionEntityDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import cn.trigram.ddo.entity.MqTransactionEntity;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

public interface MqTransactionDynamicMapper {
    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    BasicColumn[] selectList = BasicColumn.columnList(id, transactionId, log, status);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<MqTransactionEntity> insertStatement);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<MqTransactionEntity> multipleInsertStatement);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("MqTransactionEntityResult")
    Optional<MqTransactionEntity> selectOne(SelectStatementProvider selectStatement);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="MqTransactionEntityResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="transaction_id", property="transactionId", jdbcType=JdbcType.VARCHAR),
        @Result(column="log", property="log", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.VARCHAR)
    })
    List<MqTransactionEntity> selectMany(SelectStatementProvider selectStatement);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, mqTransactionEntity, completer);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, mqTransactionEntity, completer);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int deleteByPrimaryKey(String id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int insert(MqTransactionEntity record) {
        return MyBatis3Utils.insert(this::insert, record, mqTransactionEntity, c ->
            c.map(id).toProperty("id")
            .map(transactionId).toProperty("transactionId")
            .map(log).toProperty("log")
            .map(status).toProperty("status")
        );
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int insertMultiple(Collection<MqTransactionEntity> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, mqTransactionEntity, c ->
            c.map(id).toProperty("id")
            .map(transactionId).toProperty("transactionId")
            .map(log).toProperty("log")
            .map(status).toProperty("status")
        );
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int insertSelective(MqTransactionEntity record) {
        return MyBatis3Utils.insert(this::insert, record, mqTransactionEntity, c ->
            c.map(id).toPropertyWhenPresent("id", record::getId)
            .map(transactionId).toPropertyWhenPresent("transactionId", record::getTransactionId)
            .map(log).toPropertyWhenPresent("log", record::getLog)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
        );
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default Optional<MqTransactionEntity> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, mqTransactionEntity, completer);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default List<MqTransactionEntity> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, mqTransactionEntity, completer);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default List<MqTransactionEntity> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, mqTransactionEntity, completer);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default Optional<MqTransactionEntity> selectByPrimaryKey(String id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, mqTransactionEntity, completer);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    static UpdateDSL<UpdateModel> updateAllColumns(MqTransactionEntity record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalTo(record::getId)
                .set(transactionId).equalTo(record::getTransactionId)
                .set(log).equalTo(record::getLog)
                .set(status).equalTo(record::getStatus);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(MqTransactionEntity record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalToWhenPresent(record::getId)
                .set(transactionId).equalToWhenPresent(record::getTransactionId)
                .set(log).equalToWhenPresent(record::getLog)
                .set(status).equalToWhenPresent(record::getStatus);
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int updateByPrimaryKey(MqTransactionEntity record) {
        return update(c ->
            c.set(transactionId).equalTo(record::getTransactionId)
            .set(log).equalTo(record::getLog)
            .set(status).equalTo(record::getStatus)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(comments="Source Table: mq_transaction", value="DynamicSql")
    default int updateByPrimaryKeySelective(MqTransactionEntity record) {
        return update(c ->
            c.set(transactionId).equalToWhenPresent(record::getTransactionId)
            .set(log).equalToWhenPresent(record::getLog)
            .set(status).equalToWhenPresent(record::getStatus)
            .where(id, isEqualTo(record::getId))
        );
    }
}